package com.example.mapstruct_demo.service;

import com.example.mapstruct_demo.dao.TestDao;
import com.example.mapstruct_demo.pojo.dto.UserDto;
import com.example.mapstruct_demo.pojo.entity.User;
import com.example.mapstruct_demo.service.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 77229
 */
@Service
public class TestService {

    @Autowired
    private TestDao testDao;

    public Object save(UserDto dto) {
        User user = UserMapper.INSTANCE.dto2do(dto);
        testDao.save(user);
        return "success";
    }

    public UserDto find(Long userId) {
        User user = testDao.getById(userId);
        return UserMapper.INSTANCE.do2dto(user);
    }
}
